home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Bank smakow / BankSmakow.air / BankSmakow.swf / scripts / com / makingwaves / components / CheckBoxTreeItemRenderer.as next >
Text File  |  2009-12-16  |  8KB  |  236 lines

  1. package com.makingwaves.components
  2. {
  3.    import com.makingwaves.vo.FridgeProduct;
  4.    import com.makingwaves.vo.Product;
  5.    import flash.events.Event;
  6.    import flash.events.MouseEvent;
  7.    import flash.geom.ColorTransform;
  8.    import mx.controls.CheckBox;
  9.    import mx.controls.treeClasses.TreeItemRenderer;
  10.    import mx.controls.treeClasses.TreeListData;
  11.    import mx.events.TreeEvent;
  12.    
  13.    public class CheckBoxTreeItemRenderer extends TreeItemRenderer
  14.    {
  15.       
  16.       public static const ITEM_CHECK:String = "itemCheck";
  17.        
  18.       
  19.       protected var _checkbox:CheckBox;
  20.       
  21.       public function CheckBoxTreeItemRenderer()
  22.       {
  23.          super();
  24.          this.useHandCursor = true;
  25.          this.buttonMode = true;
  26.          this.addEventListener(MouseEvent.ROLL_OVER,onMouseOver);
  27.          this.addEventListener(MouseEvent.ROLL_OUT,onMouseOut);
  28.       }
  29.       
  30.       private function setChildControl() : void
  31.       {
  32.          if(_checkbox == null)
  33.          {
  34.             _checkbox = new CheckBox();
  35.             this.addEventListener(MouseEvent.CLICK,onItemClick);
  36.             this.mouseChildren = false;
  37.             addChild(_checkbox);
  38.          }
  39.          label.styleName = "Ingredient";
  40.       }
  41.       
  42.       private function onMouseOut(param1:Event) : void
  43.       {
  44.          this.transform.colorTransform = new ColorTransform();
  45.       }
  46.       
  47.       override protected function commitProperties() : void
  48.       {
  49.          super.commitProperties();
  50.          if(data != null && data is Product)
  51.          {
  52.             _checkbox.selected = (data as FridgeProduct).selected;
  53.          }
  54.       }
  55.       
  56.       private function setParentControl() : void
  57.       {
  58.          if(_checkbox != null)
  59.          {
  60.             if(this.getChildByName(_checkbox.name) != null)
  61.             {
  62.                this.removeChild(_checkbox);
  63.             }
  64.             _checkbox = null;
  65.          }
  66.          this.addEventListener(MouseEvent.CLICK,onItemClick);
  67.          this.mouseChildren = false;
  68.          label.styleName = "";
  69.       }
  70.       
  71.       public function get checkBox() : CheckBox
  72.       {
  73.          return _checkbox;
  74.       }
  75.       
  76.       override public function set data(param1:Object) : void
  77.       {
  78.          super.data = param1;
  79.          if(param1 != null)
  80.          {
  81.             if(!TreeListData(super.listData).hasChildren)
  82.             {
  83.                setChildControl();
  84.             }
  85.          }
  86.       }
  87.       
  88.       private function onItemClick(param1:MouseEvent) : void
  89.       {
  90.          var _loc2_:TreeEvent = null;
  91.          if(this.enabled == false)
  92.          {
  93.             return;
  94.          }
  95.          if(data != null && data is Product)
  96.          {
  97.             if(!(param1.currentTarget is CheckBox))
  98.             {
  99.                _checkbox.selected = !_checkbox.selected;
  100.             }
  101.             (data as FridgeProduct).selected = _checkbox.selected;
  102.             _loc2_ = new TreeEvent(ITEM_CHECK,true);
  103.             _loc2_.item = data;
  104.             dispatchEvent(_loc2_);
  105.          }
  106.          else
  107.          {
  108.             this.disclosureIcon.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN));
  109.          }
  110.       }
  111.       
  112.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  113.       {
  114.          var _loc3_:Number = NaN;
  115.          var _loc4_:String = null;
  116.          if(super.listData != null && !TreeListData(super.listData).hasChildren)
  117.          {
  118.             setChildControl();
  119.             super.updateDisplayList(param1,param2);
  120.             _loc3_ = !!data ? Number((listData as TreeListData).indent) : Number(0);
  121.             if(disclosureIcon)
  122.             {
  123.                disclosureIcon.x = _loc3_;
  124.                _loc3_ = disclosureIcon.x + disclosureIcon.width;
  125.                disclosureIcon.setActualSize(disclosureIcon.width,disclosureIcon.height);
  126.                disclosureIcon.visible = !!data ? Boolean((listData as TreeListData).hasChildren) : false;
  127.             }
  128.             if(icon)
  129.             {
  130.                icon.x = _loc3_;
  131.                _loc3_ = icon.x + icon.measuredWidth;
  132.                icon.setActualSize(icon.measuredWidth,icon.measuredHeight);
  133.             }
  134.             if(checkBox)
  135.             {
  136.                _checkbox.x = _loc3_;
  137.                _loc3_ = checkBox.x + checkBox.measuredWidth;
  138.                checkBox.setActualSize(checkBox.measuredWidth,checkBox.measuredHeight);
  139.             }
  140.             label.x = _loc3_;
  141.             label.setActualSize(label.getExplicitOrMeasuredWidth(),measuredHeight);
  142.             if((_loc4_ = getStyle("verticalAlign")) == "top")
  143.             {
  144.                label.y = 0;
  145.                _checkbox.y = 0;
  146.                if(icon)
  147.                {
  148.                   icon.y = 0;
  149.                }
  150.                if(disclosureIcon)
  151.                {
  152.                   disclosureIcon.y = 0;
  153.                }
  154.             }
  155.             else if(_loc4_ == "bottom")
  156.             {
  157.                label.y = param2 - label.height + 2;
  158.                _checkbox.y = param2 - checkBox.height + 2;
  159.                if(icon)
  160.                {
  161.                   icon.y = param2 - icon.height;
  162.                }
  163.                if(disclosureIcon)
  164.                {
  165.                   disclosureIcon.y = param2 - disclosureIcon.height;
  166.                }
  167.             }
  168.             else
  169.             {
  170.                label.y = (param2 - label.height) / 2;
  171.                checkBox.y = (param2 - checkBox.height) / 2;
  172.                if(icon)
  173.                {
  174.                   icon.y = (param2 - icon.height) / 2;
  175.                }
  176.                if(disclosureIcon)
  177.                {
  178.                   disclosureIcon.y = (param2 - disclosureIcon.height) / 2;
  179.                }
  180.             }
  181.          }
  182.          else
  183.          {
  184.             setParentControl();
  185.             super.updateDisplayList(param1,param2);
  186.          }
  187.       }
  188.       
  189.       private function onMouseOver(param1:Event) : void
  190.       {
  191.          var _loc2_:ColorTransform = new ColorTransform();
  192.          _loc2_.color = 16610051;
  193.          this.transform.colorTransform = _loc2_;
  194.       }
  195.       
  196.       override protected function measure() : void
  197.       {
  198.          var _loc1_:Number = NaN;
  199.          super.measure();
  200.          if(_checkbox != null)
  201.          {
  202.             _loc1_ = !!data ? Number((listData as TreeListData).indent) : Number(0);
  203.             if(disclosureIcon)
  204.             {
  205.                _loc1_ += disclosureIcon.width;
  206.             }
  207.             if(icon)
  208.             {
  209.                _loc1_ += icon.measuredWidth;
  210.             }
  211.             if(label.width < 4 || label.height < 4)
  212.             {
  213.                label.width = 4;
  214.                label.height = 16;
  215.             }
  216.             if(isNaN(explicitWidth))
  217.             {
  218.                _loc1_ += label.getExplicitOrMeasuredWidth();
  219.                _loc1_ += _checkbox.getExplicitOrMeasuredWidth();
  220.                measuredWidth = _loc1_;
  221.                measuredHeight = Math.max(_checkbox.getExplicitOrMeasuredHeight(),label.getExplicitOrMeasuredHeight());
  222.             }
  223.             else
  224.             {
  225.                label.width = Math.max(explicitWidth - (_loc1_ + _checkbox.getExplicitOrMeasuredWidth()),4);
  226.                measuredHeight = Math.max(_checkbox.getExplicitOrMeasuredHeight(),label.getExplicitOrMeasuredHeight());
  227.                if(icon && icon.measuredHeight > measuredHeight)
  228.                {
  229.                   measuredHeight = icon.measuredHeight;
  230.                }
  231.             }
  232.          }
  233.       }
  234.    }
  235. }
  236.